package sg.nus.iss.vmcs.controllers;

import sg.nus.iss.vmcs.gui.SimulatorControlPanel;


// Copyright 1997 ISS.
// The contents contained in this document may not be reproduced in any
// form or by any means, without the written permission of ISS, other
// than for the purpose for which it has been supplied.
//
// Author: Olivo Miotto
//

/**
 * Controller for the Simulator Control Panel <br><br>
 * Modifications:
 * <li>Philip - 29/12/2010 - Tidied up class and implemented setupCustomer</li>
 * <br><br>
 * @author Olivo Miotto
 * @author Philip Chew
 */
public class SimulationController {
	
	/** Main Controller, Controller of this Class */
	private MainController			mCtrl = null;
	
	/** Simulator Control Panel, UI managed by this Controller */
	private SimulatorControlPanel	scp = null;
    
	/**
	 * Creates an instance of the Simulation Controller
	 * @param ctrl Reference to the MainController
	 */
    public SimulationController (MainController  ctrl) {
    	mCtrl = ctrl;
    }
    
    /**
     * Returns a reference to the MainController
     * @return MainController
     */
    public MainController  getMainController() {
    	return mCtrl;
    }

    /**
     * Returns the reference to the SimulatorControlPanel
     * @return SimulatorControlPanel
     */
    public SimulatorControlPanel getSimulatorControlPanel () {
    	return scp;
    }

    /**
     * Displays the Simulator Control Panel
     */
    public void displaySimulatorControlPanel () {
    	if(scp == null ) scp = new SimulatorControlPanel (this);
        scp.display();
    }

    /**
     * Stops the entire simulation by getting Main Controller to close down
     */
    public void stop () {
        mCtrl.closeDown ();
    }

    /**
     * Closes down the Simulator Control Panel
     */
    public void closeDown() {
    	scp.closeDown();
    }

    /**
     * Starts the Simulation
     */
    public void start(){
    	scp.setSimulationActive (true);
     	scp.setActive(SimulatorControlPanel.BEGIN, false);
    }

    /**
     * Sets the state of the Simulation
     * @param vl True to activate, false to deactivate
     */
    public void setSimulationActive(boolean vl) {
    	scp.setSimulationActive(vl);
    }
    
    /**
     * Sets up the Customer Panel
     * Needed to be filled in by student;
     */
    public void setupCustomer() {
    	TransactionController tctrl = mCtrl.getTransactionController();
    	scp.setActive(SimulatorControlPanel.ACT_CUSTOMER, false);
    	tctrl.displayCustomerPanel();
    }

    /**
     * Sets up the Maintainer's Panel
     */
    public void setupMaintainer(){
        MaintenanceController mctrl = mCtrl.getMaintenanceController();
        scp.setActive(SimulatorControlPanel.ACT_MAINTAINER, false);
        mctrl.displayMaintenancePanel();
    }

    /**
     * Sets up the Machinery Panel
     * Machinery's Drink and Coin display will liase with store themselves
     * Do not need to explicitly display
     */
    public void setupSimulator() {
    	
    	MachineryController machineCtrl = mCtrl.getMachineryController();
    	scp.setActive(SimulatorControlPanel.ACT_MACHINERY, false);
      
		// activate when not login
		// always display the door locked; isOpen false
		machineCtrl.displayMachineryPanel();
         
		// display door status
		machineCtrl.displayDoorStatus();
    }
}

